package com.example.demo.utils.pay;


import com.example.demo.pay.PayNeedData;
import com.github.wxpay.sdk.WXPay;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 *
 */
@Component
public class WxPay {

	private MyWXPayConfig wxPayConfig;

	public WxPay(MyWXPayConfig wxPayConfig) {
		this.wxPayConfig = wxPayConfig;
	}

	public  Map  pay(PayNeedData payNeedData){
		//	微信支付：申请支付链接
		WXPay wxPay = new WXPay(wxPayConfig);
		HashMap<String,String> data = new HashMap<>();
		data.put("body",payNeedData.getGoodName());
		data.put("out_trade_no",payNeedData.getOrderId());
		data.put("fee_type","CNY");//币种
		data.put("total_fee", new Double(payNeedData.getPrice()*100).intValue()+"");//总金额
		data.put("trade_type","NATIVE");//总金额
		data.put("notify_url","http://v490c76704.yicp.fun/pay/wxSuccess");
//		data.put("redirect_url","http://www.baidu.com");
		Map<String,String> resp = new HashMap<>();
		try {
			resp = wxPay.unifiedOrder(data);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resp;

	}

}
